const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin")
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
    mode: 'development',  // production 生成环境下是不会产生 sourceMap的 所以devtool不需要
    devtool: false,
    optimization: {
      usedExports: true,
      minimize: true, //允许使用minimizer中的插件
      minimizer: [
        new CssMinimizerPlugin(),
        new TerserPlugin({
          extractComments: false
        })
      ]
    },
    plugins: [
      // 拷贝public
      new CopyWebpackPlugin({
        patterns: [
          {
            from: 'public', //拷贝的地方
            //忽略 public/index.html
            globOptions: {
              ignore: ['**/index.html']
            }
          }
        ]
      }),
      new MiniCssExtractPlugin({
        filename: 'css/[name].[hash:8].css'
      })
    ]
  }